<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Post Form
 *
 * @author neozilon
 */
class Admin_Form_Post extends Zend_Form{

    public function addPost(){
        $this->setName('add_post_form');
        $this->setAction('/admin/post/add')
              ->setMethod('post');
        $this->setAttrib('id', 'post_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('post');

        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Titulo:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input')
                ->setAttrib('style', 'width: 650px;')
                ->setValue('')
                ->addValidator('notEmpty');

        $postObj = new Nosql_Model_Mysql_Category();
        $options = $postObj->getCategories();

        $parents = array();
        if ($options){
            foreach ($options as $post){
                $parents[$post['categoryid']] = $post['name'];
            }
        }

        $category = new Zend_Form_Element_Select('category');
        $category->setLabel('Categoria: ')
                ->setAttrib('style', 'width: 650px;')
            ->setMultiOptions($parents);

        $tags = new Zend_Form_Element_Text('tags');
        $tags->setLabel('Etiquetas (separadas por coma ","):')
                ->setAttrib('class', 'text-input')
                ->setAttrib('style', 'width: 650px;')
                ->setValue('');


        $content = new Zend_Form_Element_Textarea('content');
        $content->setAttrib("class", "text-input textarea wysiwyg");


        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Agregar Artículo")
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($title, $category, $tags, $content,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }

    public function editPost($postId){
         $this->setName('edit_post_form');
        $this->setAction('/admin/post/edit/post/' . $postId)
              ->setMethod('post');
        $this->setAttrib('id', 'post_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('post');

        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Titulo:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input')
                ->setAttrib('style', 'width: 650px;')
                ->setValue('')
                ->addValidator('notEmpty');

        $postObj = new Nosql_Model_Mysql_Category();
        $options = $postObj->getCategories();

        $parents = array();
        if ($options){
            foreach ($options as $post){
                $parents[$post['categoryid']] = $post['name'];
            }
        }

        $category = new Zend_Form_Element_Select('category');
        $category->setLabel('Categoria: ')
                ->setAttrib('style', 'width: 650px;')
            ->setMultiOptions($parents);

        $tags = new Zend_Form_Element_Text('tags');
        $tags->setLabel('Etiquetas (separadas por coma ","):')
                ->setAttrib('class', 'text-input')
                ->setAttrib('style', 'width: 650px;')
                ->setValue('');


        $content = new Zend_Form_Element_Textarea('content');
        $content->setAttrib("class", "text-input textarea wysiwyg");


        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Editar Artículo")
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($title, $category, $tags, $content,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }

    public function searchPost(){
        $this->setName('search_post_form');
        $this->setAction('/admin/post/search')
              ->setMethod('post');
        $this->setAttrib('id', 'search_post_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('post');

        $query = new Zend_Form_Element_Text('q');
        $query->setLabel('Texto:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');

        $fields = array(1  =>'Titulo',
                        2 =>'Nombre Categoría',
                        3 =>'Tag',
                        4 =>'Contenido',
                        5 =>'Id Categoría'

            );
        $field = new Zend_Form_Element_Select('field');
        $field->setLabel('Buscar en campo:')
            ->setMultiOptions($fields);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Buscar Artículo: ')
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($query, $field,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }
}
